package api.localTime;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

/*
* LocalDate类获取本地日期：年月日，星期
* LocalTime类获取本地时间：时分秒，毫秒
* LocalDateTime类获取本地日期时间：年月日时分秒，毫秒
*
* LocalDate类常用方法：
* 1.now()-->获取当前日期
* 2.of(int year,int month,int day)-->获取指定日期
* 3.getYear()-->获取年【年月日获取类似】
* 7.plusDays(long days) -->获取当前日期加几天
* 8.minusDays(long days) -->获取当前日期减几天
*
* */
public class Test {
    public static void main(String[] args) {
        LocalDateTime now = LocalDateTime.now();
        System.out.println(now);//2025-09-13T10:59:48.665284200
        System.out.println("今年是："+now.getYear()+"年");//2025
        System.out.println("今年已经过了："+now.getDayOfYear()+"天");//256

        //加5天
        LocalDateTime newDay = now.plusDays(5);
        System.out.println("加了5天："+newDay);
        //判断两个日期是否相等、谁在谁之后
        System.out.println(now.isEqual(newDay));
        System.out.println(now.isBefore(newDay));
        System.out.println(now.isAfter(newDay));

        //日期格式化对象
        DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy年MM月dd日 HH:mm:ss");
        System.out.println(dtf.format(now));

    }
}
